import { FC, useState, useEffect } from "react";

interface PropType {
  count: number;
  name: string;
  onAbc: (n: number) => void;
}

// const Child = (props: PropType) => {
//   return <div>child子组件 - {props.count}</div>;
// };

// let timer: NodeJS.Timeout;
const Child: FC<PropType> = (props) => {
  const [num, setNum] = useState<number>(5);

  useEffect(() => {
    if (num > 0) {
      setTimeout(() => {
        setNum((v) => v - 1);
      }, 1000);
    }

    // return () => {
    //   clearInterval(timer);
    // };
  }, [num]);

  // useEffect(() => {
  //   if (num === 0) {
  //     clearInterval(timer);
  //   }
  // }, [num]);

  return (
    <div>
      child子组件 - {props.count} - {num ? num : "活动开始"}
    </div>
  );
};

export default Child;
